<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增劳务派遣')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<style>
    .jltable{
        margin: auto;
    }
    .jltable th,td{
        min-height: 40px;
        min-width: 50px;
        border: 1px solid #eee;
        padding: 10px;
    }
</style>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-lwpq-add">
            <h4 class="form-header h4">派遣管理</h4>
            <table class="jltable">
                <tr>
                    <td><label class=" control-label">姓名</label></td>
                    <td>
                        <select  class="form-control" id="name_select"></select>
                        <input name="name" class="form-control" type="hidden">
                    </td>
                    <td><label class=" control-label">身份证</label></td>
                    <td><input name="sfzh" class="form-control" type="text"></td>
                </tr>
                <tr>
                    <td><label class=" control-label is-required">派遣单位</label></td>
                    <td><input name="pqdw" class="form-control" type="text" required></td>
                    <td><label class=" control-label">薪资</label></td>
                    <td><input name="xz" class="form-control" type="text"></td>
                </tr>
                <tr>
                    <td><label class=" control-label">部门</label></td>
                    <td><input name="bm" class="form-control" type="text"></td>
                    <td><label class=" control-label">岗位</label></td>
                    <td><input name="gw" class="form-control" type="text"></td>
                </tr>
                <tr>
                    <td><label class=" control-label">开始时间</label></td>
                    <td>
                        <div class="input-group date">
                            <input name="kssj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </td>
                    <td> <label class=" control-label">结束时间</label></td>
                    <td>
                        <div class="input-group date">
                            <input name="jssj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td><label class=" control-label">工作内容</label></td>
                    <td colspan="3"><textarea name="gznr" class="form-control"></textarea></td>
                </tr>
                <tr>
                    <td> <label class=" control-label">备注</label></td>
                    <td colspan="3"> <textarea name="bz" class="form-control"></textarea></td>
                </tr>
            </table>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "lwpq/lwpq"
        $("#form-lwpq-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-lwpq-add').serialize());
            }
        }

        $("input[name='kssj']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='jssj']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function (){
            function formatRepo(repo){
                return  repo.name || repo.text;
            }
            function formatRepoSelection(repo){
                return  repo.name || repo.text;
            }

            $('#name_select').select2({
                ajax:{
                    url: ctx + 'lwpq/jl/list',
                    type:'post',
                    dataType:'json',
                    data:function (params) {
                        let query = {
                            name:params.term,
                            zt:'',
                        }
                        return query;
                    },
                    processResults : function (data){
                        let res = new Array();
                        data.rows.forEach(value => {
                            res.push({
                                id : value.id,
                                text : value.name,
                                ob:value
                            })
                        })
                        return {
                            results : res
                        };
                    },
                    minimumInputLength : 1,
                    maximumInputLength : 20,
                    templateResult : formatRepo,
                    templateSelection : formatRepoSelection,
                }
            })
            $('#name_select').on('select2:select', function (e) {
                // 处理业务
                let ob =  e.params.data.ob;
                $("input[name='sfzh']").val(ob.sfzh);
                $("input[name='name']").val(ob.name);
            });
        })
    </script>
</body>
</html>